<%@page import="org.springframework.security.core.context.SecurityContextHolder"%>
<%@page import="org.apache.commons.lang.StringUtils"%>
<%@page import="org.apache.commons.lang.time.DateFormatUtils"%>
<%@page import="org.springframework.util.CollectionUtils"%>
<%@page import="java.util.Collection"%>
<%@ include file="../common/common_include.jsp"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	UserInfo user = (UserInfo)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
	String username = user.getName();
	String siteid = user.getSiteId();
	String defaultSiteId = request.getAttribute("defaultSiteId")+"";
%>

<style>
	.selectHour-split{
		padding:0 2px;
		margin-right:5px;	
	}
	.selectMinute-split{
		padding:0 2px;
	}
</style>

<div>
	<form onsubmit="someFunc()" id="LeaveAddForm" target="_coreIframe" method="post" action="<%=request.getContextPath()%>/check/doAddSchedule" enctype="multipart/form-data">
		<div class="breadcrumb">
			<div class="bcIcon"></div>
			<ul class="bcNav">
				<li>人员排班</li>
			</ul>
		</div>
		<input type="hidden" name="userid"> 		
		<table class="formTable">
			<tr>
				<td class="tdTitle">所属公司：</td>
				<td>
					<select id="siteList" class="easyui-combobox" name="siteid" style="width:100px;"></select>
					<span class="errorTipWrap" id="errorTip_siteid"></span>
				</td>
			</tr>
			<tr>
				<td class="tdTitle">员工：</td>
				<td>
					<ul id="users"></ul>
					<span class="errorTipWrap" id="errorTip_userid"></span>
				</td>
			</tr>	
			
			<tr>
				<td class="tdTitle"></td>
				<td>添加班次</td>
			</tr>
			<tr>
				<td class="tdTitle">选择班次：</td>
				<td>
					<select id="shiftid" class="easyui-combobox" name="shiftid" style="width:200px;"></select>
					<span class="errorTipWrap" id="errorTip_userid"></span>
				</td>
			</tr>
			<tr class="tr_time_during_next">
				<td class="tdTitle">排班开始日期：</td>
				<td>
				<input class="inputText xxs" type="text" value="" name="startDate" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})">
				<span class="errorTipWrap" id="errorTip_startDate"></span>
				</td>
			</tr>
			<tr>
				<td class="tdTitle">排班结束日期：</td>
				<td>
				<input class="inputText xxs" type="text" value="" name="endDate" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})">
				<span class="errorTipWrap" id="errorTip_startDate"></span>
				</td>
			</tr>
<!-- 			<tr>
				<td class="tdTitle"></td>
				<td>添加第二个班次</td>
			</tr>
			<tr>
				<td class="tdTitle">选择班次：</td>
				<td>
					<select id="shiftid2" class="easyui-combobox" name="shiftid2" style="width:200px;"></select>
					<span class="errorTipWrap" id="errorTip_userid"></span>
				</td>
			</tr>
			<tr class="tr_time_during_next">
				<td class="tdTitle">排班开始日期：</td>
				<td>
				<input class="inputText xxs" type="text" value="" name="startDate2" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})">
				<span class="errorTipWrap" id="errorTip_startDate"></span>
				</td>
			</tr>
			<tr>
				<td class="tdTitle">排班结束日期：</td>
				<td>
				<input class="inputText xxs" type="text" value="" name="endDate2" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})">
				<span class="errorTipWrap" id="errorTip_startDate"></span>
				</td>
			</tr>
			<tr>
				<td class="tdTitle"></td>
				<td>添加第三个班次</td>
			</tr>
			<tr>
				<td class="tdTitle">选择班次：</td>
				<td>
					<select id="shiftid3" class="easyui-combobox" name="shiftid3" style="width:200px;"></select>
					<span class="errorTipWrap" id="errorTip_userid"></span>
				</td>
			</tr>
			<tr class="tr_time_during_next">
				<td class="tdTitle">排班开始日期：</td>
				<td>
				<input class="inputText xxs" type="text" value="" name="startDate3" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})">
				<span class="errorTipWrap" id="errorTip_startDate"></span>
				</td>
			</tr>
			<tr>
				<td class="tdTitle">排班结束日期：</td>
				<td>
				<input class="inputText xxs" type="text" value="" name="endDate3" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})">
				<span class="errorTipWrap" id="errorTip_startDate"></span>
				</td>
			</tr>
			<tr>
				<td class="tdTitle"></td>
				<td>添加第四个班次</td>
			</tr>
			<tr>
				<td class="tdTitle">选择班次：</td>
				<td>
					<select id="shiftid4" class="easyui-combobox" name="shiftid4" style="width:200px;"></select>
					<span class="errorTipWrap" id="errorTip_userid"></span>
				</td>
			</tr>
			<tr class="tr_time_during_next">
				<td class="tdTitle">排班开始日期：</td>
				<td>
				<input class="inputText xxs" type="text" value="" name="startDate4" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})">
				<span class="errorTipWrap" id="errorTip_startDate"></span>
				</td>
			</tr>
			<tr>
				<td class="tdTitle">排班结束日期：</td>
				<td>
				<input class="inputText xxs" type="text" value="" name="endDate4" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})">
				<span class="errorTipWrap" id="errorTip_startDate"></span>
				</td>
			</tr>
			<tr>
				<td class="tdTitle"></td>
				<td>添加第五个班次</td>
			</tr>
			<tr>
				<td class="tdTitle">选择班次：</td>
				<td>
					<select id="shiftid5" class="easyui-combobox" name="shiftid5" style="width:200px;"></select>
					<span class="errorTipWrap" id="errorTip_userid"></span>
				</td>
			</tr>
			<tr class="tr_time_during_next">
				<td class="tdTitle">排班开始日期：</td>
				<td>
				<input class="inputText xxs" type="text" value="" name="startDate5" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})">
				<span class="errorTipWrap" id="errorTip_startDate"></span>
				</td>
			</tr>
			<tr>
				<td class="tdTitle">排班结束日期：</td>
				<td>
				<input class="inputText xxs" type="text" value="" name="endDate5" onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})">
				<span class="errorTipWrap" id="errorTip_startDate"></span>
				</td>
			</tr>			 -->
			<!-- 
			<tr class="tr_time_during_pre">
				<td class="tdTitle"></td>
				<td class="" colspan="2">考勤日各时间段设置
				</td>
			</tr>
			<tr class="tr_time_during">
				<td class="tdTitle">第1时间段：</td>
				<td class="" colspan="2">
						<div class="checkbox-wrap">
							<input type="hidden" name="workDays">
							<label>
								<input type="checkbox" class="checkbox workDays_checkbox" s="1">
								<span>星期一</span>
							</label>
							<label>
								<input type="checkbox" class="checkbox workDays_checkbox" s="2">
								<span>星期二</span>
							</label>
							<label>
								<input type="checkbox" class="checkbox workDays_checkbox" s="3">
								<span>星期三</span>
							</label>
							<label>
								<input type="checkbox" class="checkbox workDays_checkbox" s="4">
								<span>星期四</span>
							</label>
							<label>
								<input type="checkbox" class="checkbox workDays_checkbox" s="5">
								<span>星期五</span>
							</label>
							<label>
								<input type="checkbox" class="checkbox workDays_checkbox" s="6">
								<span>星期六</span>
							</label>
							<label>
								<input type="checkbox" class="checkbox workDays_checkbox" s="7">
								<span>星期日</span>
							</label>
						</div>
					</td>
			</tr>
			 -->
		
			<tr>
				<td class="tdTitle">特殊设置：</td>
				<td class="" colspan="2">
						<div class="checkbox-wrap">
							<label>
								<input id="setTop" type="checkbox" value="1" name="isCheck" class="checkbox">
								<span>是否考勤</span>
							</label>
							<label>
								<input id="setImportant" type="checkbox" value="1" name="isHoliday" class="checkbox">
								<span>节假日有效</span>
							</label>
							<label>
								<input id="setImportant" type="checkbox" value="1" name="isOvertime" class="checkbox">
								<span>计算加班</span>
							</label>
						</div>
					</td>
			</tr>
			<tr>
				<td class="tdTitle"></td>
				<td>
					<div>
						<input class="input-btn-microsoft" type="submit" value="提交">
						<a class="a-btn-microsoft" href="javascript:XF.NAV.navTo('/check')">取消</a>
					</div>
				</td>
			</tr>	
		</table>
		<input type="hidden" value="<%=username %>" name="addUser"> 	
	</form>
	<iframe id="_coreIframe" name="_coreIframe" style="display: none;"></iframe>
</div>
<script>
$('#siteList').combobox({
	url:global.contextPath + '/company/siteList',
	valueField:'siteid',
	textField:'sitename',
	onSelect:function(record){
		XF.Check.DefaultSiteId = record.siteid;
		$("#shiftid").combobox('reload',global.contextPath + '/check/shiftListBySiteId?siteid='+record.siteid);
		getDeptsAndUsers(record.siteid);
	}
});

$('#siteList').combobox('setValue', '<%=defaultSiteId %>');

function getDeptsAndUsers(siteid) {
	$('#users').find('li').remove();
	$('#users').tree({
		url: global.contextPath + '/company/deptsAndUsers?siteid=' + siteid ,
		checkbox: true
	});
};

function someFunc() {
    var nodes = $('#users').tree('getChecked');
    var s = '';
    for(var i=0; i<nodes.length; i++){
    	if(nodes[i].id.match('D'))
    		continue;
        if (s != '') s += ',';
       	s += nodes[i].id;
    }
    $("input[name=userid]").val(s);
};

getDeptsAndUsers('<%=defaultSiteId %>');

XF.Check.DefaultSiteId = '<%=defaultSiteId %>';
XF.Check.init();
</script>


